package com.group9.controller;

import com.group9.pojo.Admin;
import com.group9.service.LoginService;
import com.group9.service.impl.LoginServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by Lcouncillor on 2020/4/10.
 */
@WebServlet(name = "LoginServlet", urlPatterns = "/login.do")
public class LoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String userName = request.getParameter("username");
        String password = request.getParameter("password");
        String rem = request.getParameter("remember");
        String action = request.getParameter("action");

        if ("admin".equals(action)){
            LoginService loginService = new LoginServiceImpl();
            Admin admin = loginService.adLogin(userName,password);

            if (admin != null){
                response.getWriter().write("success");
            }
        }

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
